; x^2 = x + 1, 两边同除 x，
; x = 1 + 1/x


(define tolerance 0.00001)

(define (close-enough? v1 v2)
    (< (abs (- v1 v2)) tolerance))

(define (fixed-point f first-guess)
    (define (try guess)
        (let ((next (f guess)))
            (if (close-enough? guess next)
                next
                (try next))))
    (try first-guess))

(define (phi first-guess)
    (fixed-point (lambda (x) (+ 1 (/ 1 x))) first-guess))

(display "\n========================================\n")
(display (fixed-point cos 1.0))
(newline)
(display (phi 1.0))
(display "\n========================================\n")
